package es.ignapziriza.ccrypto.testing;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import es.ignapziriza.ccrypto.ciphers.substitution.VigenereCipher;

public class VigenereCipherTesting {

	private VigenereCipher vigCiphering;

	@Before
	public void setUp() throws Exception {
		vigCiphering = new VigenereCipher();
	}

	@After
	public void tearDown() throws Exception {
		vigCiphering = null;
	}

	@Test
	public void testCipherText1() {
		vigCiphering.setKeyword("CAT");
		assertEquals("CATBDEFGHIJKLMNOPQRSUVWXYZ",
				vigCiphering.getCipherAlphabet());
	}

	@Test
	public void testCipherText2() {
		vigCiphering.setKeyword("CAT");
		vigCiphering.cipher("ATTACK AT DAWN");
		assertEquals("CSSCTJ CS BCWM", vigCiphering.getCipheredText());
	}

	@Test
	public void testDecipherText1() {
		vigCiphering.setKeyword("CAT");
		vigCiphering.decipher("CSSCTJ CS BCWM");
		assertEquals("ATTACK AT DAWN", vigCiphering.getCipheredText());
	}

	@Test
	public void testFormatForTransmission1() {
		try {
			vigCiphering.setKeyword("CAT");
			vigCiphering.cipher("ATTACK AT DAWN");
			vigCiphering.formatForTransmission(6);
			assertEquals("CTMCCD CTWCWG", vigCiphering.getCipheredText());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	public void testFormatForTransmission2() {
		try {
			vigCiphering.setKeyword("CAT");
			vigCiphering.cipher("ATTACK AT DAWN");
			vigCiphering.formatForTransmission(7);
		} catch (Exception e) {
			assertTrue("Esto sale si falla el test",
					e.getMessage().contains("char"));
		}
	}

}
